﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ALinq.BBS.DataAccess
{
    public partial class Users : IQueryable<User>
    {
        Database dataContext;
        IQueryable<User> source;

        IQueryable<User> Source
        {
            get
            {
                if (source == null)
                {
                    source = DataContext.Users;
                }
                return source;
            }
        }

        public void Add(User user)
        {
            DataContext.Users.InsertOnSubmit(user);
            DataContext.SubmitChanges();
        }

        public void Delete(User user)
        {
            DataContext.Users.DeleteOnSubmit(user);
        }

        public void SubmitChanges()
        {
            DataContext.SubmitChanges();
        }

        internal Database DataContext
        {
            get
            {
                if (dataContext == null)
                    dataContext = new Database();

                return dataContext;
            }
        }

        #region IEnumerable<User> Members

        public IEnumerator<User> GetEnumerator()
        {
            return Source.GetEnumerator();
        }

        #endregion

        #region IEnumerable Members

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return Source.GetEnumerator();
        }

        #endregion

        #region IQueryable Members

        public Type ElementType
        {
            get { return Source.ElementType; }
        }

        public System.Linq.Expressions.Expression Expression
        {
            get { return Source.Expression; }
        }

        public IQueryProvider Provider
        {
            get { return Source.Provider; }
        }

        #endregion
    }
}
